package spl.utils;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class UrlGet {
	public static void get(String a, PrintWriter res)
	{
		try
		{
			URL		url;
			URLConnection	urlConn;
			DataInputStream	input;

			url = new URL (a);

			// URL connection channel.
			urlConn = url.openConnection();
			urlConn.setDoInput (true);
			urlConn.connect();

			// Get response data.
			input = new DataInputStream (urlConn.getInputStream ());

			String str;
			while (null != ((str = input.readLine()))) {
				res.println (str);
			}

			input.close ();

		}
		catch (IOException ioe) {
			System.err.println("IOException in UrlGet: " + ioe.getMessage());
		}
	}
	
	public static HttpURLConnection connection(String url) throws IOException {
		URL urlObj = new URL(url);
		HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
		
		return conn;
	}
}
